package com.atwy.account.service.Impl;

import com.atwy.account.mapper.AccountMapper;
import com.atwy.account.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    AccountMapper accountMapper;

    @Override
    public boolean debit(String userId, int money) {
        accountMapper.deduct(userId, money);
        int moneyByUserId = accountMapper.getMoneyByUserId(userId);
        if (moneyByUserId >= 0) {
            return true;
        }
        throw new RuntimeException("余额不足");
    }
}
